package gupao.concurrency.primenum;

public class PrimeCalculator {
    public boolean isPrime(int num){
        if(num <= 1){
            return false;
        }
        int h = (int) Math.sqrt(num);
        for(int i = 2; i <= h; i++){
            if(num % i == 0){
                return false;
            }
        }
        return true;
    }
    /**
     * @param lo include
     * @param hi exclude
     * @return prime number
     */
    public int countPrimeInRange(int lo, int hi){
        int count = 0;
        for(int num = lo; num < hi; num++){
            if(isPrime(num)){
                count++;
            }
        }
        return count;
    }
}
